{php}$namespace=ns('extendfield');{/php}
<script>
    Namespace.register("EBCMS.{$namespace}");
    $(function(){
        EBCMS.{$namespace}.queryParams = {
            order:{
                'sort':'desc',
            },
            model:'admin/extendfield',
        };
        EBCMS.{$namespace}.refresh = function refresh(p){
            if (p) {
                $.each(p, function(index, val) {
                    if (typeof val == 'object') {
                        EBCMS.{$namespace}.queryParams[index] = $.extend(EBCMS.{$namespace}.queryParams[index], p[index]);
                        delete p[index];
                    };
                });
                $.extend(EBCMS.{$namespace}.queryParams, p);
            };
            EBCMS.CORE.api({
                queryParams:EBCMS.{$namespace}.queryParams,
                group:'group',
                tpl:'{$namespace}-table',
                target:'#{$namespace}_table',
                compileAfter:function(data){
                    $('#{$namespace}_table').find('.input_sort').focus(function(){
                        EBCMS.{$namespace}.sortvalue = $(this).val();
                    }).blur(function(){
                        var $this = $(this);
                        if ($this.val() != EBCMS.{$namespace}.sortvalue) {
                            EBCMS.ACT.togglefield('{:url('extendfield/resort')}',$this.data('id'),$this.val(),'{$namespace}','resort');
                        };
                    });
                    $('#{$namespace}_table').find('tr').bind('click', function(event) {
                        $(this).addClass('warning').siblings('tr').removeClass('warning');
                    });
                    EBCMS.FN.renderFilter({
                        namespace:'{$namespace}',
                        filter:{
                            search:{
                                field:'group|title|name|value|remark',
                                value:''
                            },
                            status:{
                                field:'status',
                            },
                            order:{
                                filters:{id:'id',update_time:'更新时间',sort:'权重'}
                            },
                        }
                    });
                },
            });
        };
        EBCMS.{$namespace}.add = function add(){
            if (EBCMS.{:ns()}.category_id) {
                EBCMS.CORE.get({
                    url:'{:url('extendfield/add')}',
                    queryParams:{
                        category_id:EBCMS.{:ns('extend')}.category_id,
                    },
                    target:'#lgModal .modal-content',
                });
            }else{
                EBCMS.MSG.notice('请先选择左侧模型！');
            };
        };
        EBCMS.{$namespace}.edit = function edit(id){
            EBCMS.CORE.get({
                url:'{:url('extendfield/edit')}',
                queryParams:{
                    id:id,
                },
                target:'#lgModal .modal-content',
            });
        };
        EBCMS.{$namespace}.config = function config(id){
            EBCMS.CORE.get({
                url:'{:url('extendfield/edit')}',
                queryParams:{
                    __type:'config',
                    id:id,
                },
                target:'#lgModal .modal-content',
            });
        };
    });
</script>
    
<script id="{$namespace}-box" type="text/html">
    <div class="header">
        <div class="footer-page" id="{$namespace}_filter"></div>
        <div class="header-title" onclick="EBCMS.{$namespace}.refresh();">字段管理</div>
        <div class="btn-group">
            <button class="btn btn-primary" onclick="EBCMS.{$namespace}.add();">添加</button>
        </div>
    </div>
    <div class="body" style="bottom:0px;">
        <div class="box" id="{$namespace}_table"></div>
    </div>
</script>
    
<script id="{$namespace}-table" type="text/html">
    <div class="table-responsive">
        <table class="table table-bordered table-hover table-ebcms">
            <tbody>
                <tr>
                    <!-- <th style="width:70px;">id</th> -->
                    <th style="width:245px;">操作</th>
                    <th>标题</th>
                    <th>字段</th>
                    <th>排序</th>
                </tr>
                [[each groups as data group]]
                    <tr>
                        <th>[[group]]</th>
                        <th colspan="3"></th>
                    </tr>
                    [[include '{$namespace}-table-item' data]]
                [[/each]]
            </tbody>
        </table>
    </div>
</script>

<script id="{$namespace}-table-item" type="text/html">
    [[each rows as v n]]
        <tr>
            <!-- <td>[[v.id]]</td> -->
            <td>
                <div class="btn-group btn-group-sm">
                    [[if v.status==1]]
                    <button class="btn btn-primary" onclick="EBCMS.ACT.status('{:url('extendfield/status')}','[[v.id]]','0','{$namespace}');">已审</button>
                    [[else]]
                    <button class="btn btn-warning" onclick="EBCMS.ACT.status('{:url('extendfield/status')}','[[v.id]]','1','{$namespace}');">未审</button>
                    [[/if]]
                    <button class="btn btn-primary" onclick="EBCMS.{$namespace}.edit('[[v.id]]');">编辑</button>
                    <button class="btn btn-primary" onclick="EBCMS.{$namespace}.config('[[v.id]]')">设置</a>
                    <button class="btn btn-primary" onclick="EBCMS.ACT.del('{:url('extendfield/delete')}','[[v.id]]','{$namespace}');">删除</button>
                </div>
            </td>
            <td>[[v.title]]</td>
            <td>[[v.name]]</td>
            <td><input value="[[v.sort]]" class="form-control input-sm input_sort" data-id="[[v.id]]"></td>
        </tr>
    [[/each]]
</script>